package one.one.thirtySix;

import java.util.Arrays;

import edu.princeton.cs.algs4.StdRandom;

public class Shuffle {

	static void shuffle(double[] a) {
		int N = a.length;
		for (int i = 0; i < N; i++) {
			int r = i + StdRandom.uniform(N - i);
			double temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void initialize(double[] a) {
		for (int i = 0; i < a.length; i++) {
			a[i] = i;
		}
	}

	static void reshuffle(int M, int N) {
		double[] a = new double[M];
		double[][] r = new double[M][M];

		for (int i = 0; i < N; i++) {
			initialize(a);
			shuffle(a);
			for (int j = 0; j < M; j++) {
				r[(int) a[j]][j] += 1.0;
			}
		}
		for (int i = 0; i < M; i++) {
			System.out.println(Arrays.toString(r[i]));
		}
	}

	public static void main(String[] args) {
		int M = Integer.parseInt(args[0]);
		int N = Integer.parseInt(args[1]);

		reshuffle(M, N);
	}

}
